package com.huilian.iotbox.admin.quartz.job;

import com.huilian.iotbox.admin.service.StatsAgencyService;
import com.huilian.iotbox.data.service.ErrorLogCommonService;
import com.huilian.iotbox.data.utils.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author lizhiquan
 * @CreateDate: 2021-04-14 19:28
 * @Description:
 */
@Slf4j
public class StatsDayStoreAndAgencyJob implements BaseJob {

    @Autowired
    private StatsAgencyService statsAgencyService;
    @Autowired
    private ErrorLogCommonService errorLogCommonService;

    /**
     * 每天凌晨1点 统计前一天场地信息、代理信息及分润
     *
     * @param context
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("--------------定时任务 场地信息、代理信息及分润 统计开始 时间{}---------------", DateTimeUtils.currTime());

        Exception result = statsAgencyService.statsDayStoreAndAgencyJob();
        if (result != null) {
            errorLogCommonService.writerInfoException("场地信息、代理信息及分润统计失败", null, result);
        }

        log.info("--------------定时任务 场地信息、代理信息及分润 统计结束 end时间{}---------------", DateTimeUtils.currTime());
    }

}
